FBL.ns(function() {with (FBL) { 

function getCommandLine(context) {
	return Firebug.largeCommandLine ? context.chrome.$('fbLargeCommandLine') : context.chrome.$('fbCommandLine');
}

Firebug.Console.openTechnikaConsole = function (context) {
	Firebug.toggleBar();
	technikaOpenConsole();
};

Firebug.Console.loadBookmarklet = function (context) {
	var rv = {url:null};

	window.openDialog('chrome://technika/content/selectBookmarkletDialog.xul', '', 'modal,centerscreen,chrome,dialog,resizable,dependent', rv);

	if (rv.url) {
		if (!TH_isURLBookmarklet(rv.url)) {
			var stringBundle = TH_getStringBundle('chrome://technika/locale/technika.properties');
			alert(stringBundle.GetStringFromName('selectBookmarkletError'));

			return;
		}

		var code = rv.url.substring(11);

		if (code.substring(code.length - 9, code.length) == ';void(0);') {
			code = code.substring(0, code.length - 9);
		}

		var commandLine = getCommandLine(context);
		commandLine.value = unescape(code);
	}
};

Firebug.Console.buildBookmarklet = function (context) {
	var commandLine = TH_trimString(getCommandLine(context).value);

	if (!commandLine) {
		var stringBundle = TH_getStringBundle('chrome://technika/locale/technika.properties');
		alert(stringBundle.GetStringFromName('buildBookmarkletError'));

		return;
	}

	var bookmarklet = 'javascript:' + escape(commandLine) + ';void(0);';

	window.openDialog('chrome://browser/content/bookmarks/addBookmark2.xul', '', 'modal,centerscreen,chrome,dialog,resizable,dependent', {name: null, url: bookmarklet, charset: 'UTF-8'});
};

Firebug.Console.buildBookmarkletAs = function (context) {
	var commandLine = TH_trimString(getCommandLine(context).value);

	if (!commandLine) {
		var stringBundle = TH_getStringBundle('chrome://technika/locale/technika.properties');
		alert(stringBundle.GetStringFromName('buildBookmarkletAsError'));

		return;
	}

	var bookmarklet = 'javascript:' + escape(commandLine) + ';void(0);';

	var rv = {bookmarklet:bookmarklet};

	window.openDialog('chrome://technika/content/buildBookmarkletAsDialog.xul', '', 'modal,centerscreen,chrome,dialog,resizable,dependent', rv);
};

Firebug.CommandLine._enter = Firebug.CommandLine.enter; 

Firebug.CommandLine.enter = function (context, command) {
	var commandLine = getCommandLine(context);
	var expr = TH_trimString((command ? command : commandLine.value));

	if (expr[0] == '#') {
	        if (!Firebug.largeCommandLine) {
			this.clear(context);
			this.appendToHistory(expr);

			Firebug.Console.log(expr, context, "command", FirebugReps.Text);
		} else {
			var shortExpr = cropString(stripNewLines(expr), 100);
			Firebug.Console.log(shortExpr, context, "command", FirebugReps.Text);
		}

		var bookmarks = TH_getBookmarkList();
		for (var i = 0; i < bookmarks.length; i++) {
			var url = bookmarks[i].url;
			var name = TH_trimString(bookmarks[i].name);

			if (expr.substring(1) == name) {
				TH_getSelectedBrowserWindow().location = url;
			}
		}
	} else {
		Firebug.CommandLine._enter.call(Firebug.CommandLine, context, command);
	}
};

}});
